<?
$this->placeholder('page_title')->set('Ultimate Games');
$grid_options = array('width' => 600);

$filename = dirname(__FILE__) . '/games_grid.ini';
$col = new Zend_Config_Ini($filename, 'columns');

$this->dojo()->requireModule('dijit.form.Button');

$this->headScript()->captureStart();
?>
function game_grid_edit_formatter(p)
{
    return '<a href="<?= $this->baseUrl() ?>/admin/ultimatum/gamesedit/id/'
        + p + '"><img src="<?= $this->baseUrl() ?>/images/icons/edit.gif" height="20" width="20" border="0"/></a>';
}

function game_grid_view_formatter(p)
{
    return '<a href="<?= $this->baseUrl() ?>/admin/ultimatum/gamesview/id/'
        + p + '"><img src="<?= $this->baseUrl() ?>/images/icons/view.gif" height="20" width="20" border="0"/></a>';
}

function unity_year(y)
{
    return new String(y).replace(/^20/, '');
}

var ugd_months = [
  ,
  'Jan',
  'Feb',
  'Mar',
  'Apr',
  'May',
  'Jun',
  'Jul',
  'Aug',
  'Sep',
  'Oct',
  'Nov',
  'Dec'
];

function grid_date_formatter(pDate)
{
    hits = new String(pDate).match(/([\d]{4})-([\d]{2})-([\d]{2})/)
    if (hits)
    {
	var out = ugd_months[new Number(hits[2]).valueOf()] + '&nbsp;' + new Number(hits[3]).valueOf() + '&nbsp;' + unity_year(hits[1]);

	return out;
    }
    else
    {
	return pDate;
    }
}

var selected_indexes = {};
var grid;

function render_selection()
{
    var v = '';
    for (p in selected_indexes)
    {
        v += selected_indexes[p].id + ",";
    }

    dojo.byId('selected_games').value = v;
}

<?  $this->headScript()->captureEnd();   ?>

<?= $this->dojostore('games_store', $this->baseUrl() . '/admin/ultimatum/gamesstore') ?>
<?= $this->dojogrid('game_grid', 'games_store', $col, 'id', NULL, $grid_options) ?>

<a href="<?= $this->baseUrl() ?>/admin/ultimatum/gamenew" class="linkbutton">Add game</a>
<br />
<form id="delete_form" action="/admin/ultimatum/gamesdelete" method="post">
    <button dojoType="dijit.form.Button">Delete Selected
    <script type="dojo/method" event="onClick">
        var games = dijit.byId('game_grid').selection.getSelected();
        var indexes = new Array();
        for (var i = 0; i < games.length; ++i)
        {
            indexes.push(games[i].id);
        }
        console.debug(indexes);
        if (indexes.length > 0)
            {
                alert('Delete Checked' + indexes.join(','));
                dojo.byId('delete_grid_indexes').value = indexes.join(',');
                dojo.byId('delete_form').submit();
            }
    </script>
</button>
        <input type="hidden" id="delete_grid_indexes" name="grid_indexes" />
</form>
